{include file="public/head"/} 
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>后台管理</cite></a>
        <a><cite>停车场地管理中心</cite></a>
        <a><cite>月租车辆管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{url(admin/Package/packageList)}">
          <div class="layui-input-inline">
            <select name="parkingNo" lay-filter="commname" id="commname">
              <option value="">所属停车场</option>
              {foreach $parkinglist as $parking}
              <option value="{$parking.parkingNo}" {if isset($parkingNo)}{if $parkingNo == $parking.parkingNo} selected {/if}{/if}>{$parking.parkingName}</option>
              {/foreach}
            </select>
          </div>

            <div class="layui-input-inline">
                <select name="delivery_status">
                    <option value="">下发状态</option>
                    <option value="1" {if isset($delivery_status)}{if $delivery_status == '1'}selected{/if}{/if}>已生效</option>
                    <option value="2" {if isset($delivery_status)}{if $delivery_status == '2'}selected{/if}{/if}>未下发</option>


                </select>
            </div>
            <input type="text" name="car_number"  placeholder="车牌号码" autocomplete="off" class="layui-input" value="{if isset($car_number)}{$car_number}{/if}">
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加月租车','{:url(\'caradd\')}',500,560)"><i class="layui-icon"></i>添加月租车</button>
        <button class="layui-btn layui-btn-danger" onclick="x_admin_show('批量导入','{:url(\'packageExcel\')}',600,400)"><i class="layui-icon"></i>批量导入</button>


         <button class="layui-btn" onclick="packageDump('{$export}')"><i class="layui-icon"></i>批量导出</button>

          <button class="layui-btn layui-btn-normal" onclick="packageIssuedAll()"><i class="layui-icon"></i>批量下发</button>
		<span class="x-right" style="line-height:40px">共有数据：{$number} 条</span>
      </xblock>
      <table class="layui-table" id="table">
        <thead>
          <tr >
              <th style="text-align: center; font-size: 16px;">
                  <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
              </th>
			<th style="text-align: center; font-size: 16px;width:35px">ID</th>
              <th style="text-align: center; font-size: 16px; height: 30px;">停车场编号</th>
            <th style="text-align: center; font-size: 16px; height: 30px;">停车场名称</th>
           
            <th style="text-align: center; font-size: 16px;">车牌号码</th>
            <th style="text-align: center; font-size: 16px;">车主姓名</th>
            <th style="text-align: center; font-size: 16px;">联系电话</th>
            <th style="text-align: center; font-size: 16px;">车位价格</th>
            
            <th style="text-align: center; font-size: 16px;">开始时间</th>
            <th style="text-align: center; font-size: 16px;">结束时间</th>
            <th style="text-align: center; font-size: 16px;">状态</th>
            <th style="text-align: center; font-size: 16px;">备注</th>
            <th style="text-align: center; font-size: 16px;">添加时间</th>
            <th style="text-align: center; font-size: 16px;">下发</th>
            <th style="text-align: center; font-size: 16px;">操作</th>
          </tr>
        </thead>
        <tbody>
          {foreach $list as $lis}
          <tr >
              <td style="text-align: center;">
                  <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$lis.id}'><i class="layui-icon">&#xe605;</i></div>
              </td>
			<td style="text-align: center;">{$lis.id}</td>
              <td style="text-align: center;">{$lis.parkingNo}</td>
            <td style="text-align: center;">{$lis.parkingName}</td>
           
            <td style="text-align: center;">{$lis.car_number}</td>
           <td style="text-align: center;">{$lis.owner_name}</td>
           <td style="text-align: center;">{$lis.owner_phone}</td>
            <td style="text-align: center;">{$lis.price}元</td>
            
            <td style="text-align: center;">{$lis.begin_time|date="Y-m-d H:i:s"}</td>
            <td style="text-align: center;">{$lis.end_time|date="Y-m-d H:i:s"}</td>
            <td style="text-align: center;">
              {if $lis.delivery_status == 1}
                已生效
              {elseif $lis.delivery_status ==2}
              
                <span style="color:red">未下发</span>
              
              {/if}
            </td>
            <td style="text-align: center;">{$lis.remarks}</td>
            <td style="text-align: center;">{$lis.create_at}</td>
            <td style="text-align: center;">{if $lis.delivery_status == 2}
                <span class="layui-btn layui-btn-normal " onclick="packageIssued('{$lis.id}')">下发 </span>
                {/if}</td>
            <td class="td-manage" style="text-align: center;">

				<a title="修改"  onclick="x_admin_show('修改','{:url(\'caredit\')}?id={$lis.id}',500,560)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="备注"  onclick="x_admin_show('备注','{:url(\'remarks\')}?id={$lis.id}',600,400)" href="javascript:;">
                    <i class="layui-icon">&#xe606;</i>
                </a>
                <a title="删除" onclick="packageDel('{$lis.id}')" href="javascript:;" id="{$lis.id}">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div>
            {$carlist->render()|raw}
          </div>
      </div>

    </div>
    <script>
        //批量下发
        function packageIssuedAll () {
            var datas = $('#table tbody td .layui-form-checked')
            var ids = []
            datas.each(function(index, element){
                var id = $(this).data('id')
                ids.push(id)
            })

            var str = ids.join(',');
            var count = ids.length

            $.post('{:url("packageIssuedAll")}', { id: str}, function(r){
                console.log(r);
                if (r.info) {
                    alert(r.info)
                    location.reload()
                }else{
                    alert(r.error)
                    location.reload()
                }
            })
        }
        function packageIssued(id){
            var url = '{:url("packageIssued")}'
            $.post(url, {id: id}, function(r){
                if (r.info) {
                    alert(r.info)
                    location.reload()  
                }else{
                    alert(r.error)
                    location.reload()  
                }
            })
        }

        //删除
        function packageDel(id){
            if(confirm('确定要删除吗?')){
                var url = '{:url("packageDel")}'
                $.post(url, {id: id}, function(r){
                    if (r.info) {
                        alert(r.info)
                        location.reload()
                    }else{
                        alert(r.error)
                        location.reload()
                    }
                })
            }

        }
	//批量导出
      function packageDump(exportid){
          var url = "{:url('packageDump')}?&export=" + exportid;
          layer.open({
              type: 2,
              title: '批量导出账单',
              shadeClose: true,
              shade: 0.8,
              area: ['60%', '60%'],
              content: url //iframe的url
          });
      }




    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  </body>

</html>